function Queue() {
    this.dataStore = [];
    this.enqueue = enqueue;     //向队列中添加元素
    this.dequeue = dequeue;     //从队列中弹出并返回元素
    this.front = front;     //返回队列开头的元素
    this.back = back;       //返回队列末尾的元素
    this.isEmpty = isEmpty;     //判断队列是否为空
}

let enqueue = function (element) {
    this.dataStore.push(element);
}

let dequeue = function () {
    return this.dataStore.shift();
}

let front = function () {
    return this.dataStore[0];
}

let back = function () {
    return this.dataStore[this.dataStore.length - 1];
}

let isEmpty = function () {
    return this.dataStore.length === 0 ? true : false;
}

let queue = new Queue();
queue.enqueue(1);
console.log(queue.dequeue());

//基数排序
const nums = [21, 31, 32, 53, 23, 21, 32];  //nums是一个0~99的整数数组

function contribute(nums) {
    const queueArray = [];
    for (let i = 0; i < nums.length; i++) {
        queueArray[i] = new Queue();
    };

    nums.forEach((item, index) => {
        queueArray[item % 10].enqueue(item);
    });

    const tempNums = [];
    queueArray.forEach((item) => {
        while (!item.isEmpty()) {
            tempNums.push(item.dequeue());
        }
    });

    const result = [];
    tempNums.forEach((item) => {
        queueArray[parseInt(item / 10)].enqueue(item);
    });
    queueArray.forEach((item) => {
        while (!item.isEmpty()) {
            result.push(item.dequeue());
        }
    });
    return result;
};

console.log(contribute(nums));